package com.sugon.controller.tool;

import com.sugon.entity.ToolsCheckRecordEntity;
import com.sugon.service.ToolsCheckRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 工装校对记录Controller
 *
 * @author sugon
 * @date 2019-08-14 08:25:51
 */
@Controller
@RequestMapping("toolscheckrecord")
public class ToolsCheckRecordController {
    @Autowired
    private ToolsCheckRecordService toolsCheckRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<ToolsCheckRecordEntity> toolsCheckRecordList = toolsCheckRecordService.queryList(query);
        int total = toolsCheckRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(toolsCheckRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("toolscheckrecord:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        ToolsCheckRecordEntity toolsCheckRecord = toolsCheckRecordService.queryObject(id);

        return R.ok().put("toolsCheckRecord", toolsCheckRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("toolscheckrecord:save")
    @ResponseBody
    public R save(@RequestBody ToolsCheckRecordEntity toolsCheckRecord) {
        toolsCheckRecordService.save(toolsCheckRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("toolscheckrecord:update")
    @ResponseBody
    public R update(@RequestBody ToolsCheckRecordEntity toolsCheckRecord) {
        toolsCheckRecordService.update(toolsCheckRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("toolscheckrecord:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        toolsCheckRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<ToolsCheckRecordEntity> list = toolsCheckRecordService.queryList(params);

        return R.ok().put("list", list);
    }
    /**
     * 抽查
     */
    @RequestMapping("/sample")
    @RequiresPermissions("toolscheckrecord:sample")
    @ResponseBody
    public R sample(@RequestParam Map<String, Object> params) {
        String id = params.get("id") + "";
        String remark = params.get("remark") + "";
        int sampleStatus = Integer.parseInt(params.get("sampleStatus") + "");
        ToolsCheckRecordEntity toolsCheckRecord = new ToolsCheckRecordEntity();
        toolsCheckRecord.setId(id);
        toolsCheckRecord.setRemark(remark);
        toolsCheckRecord.setSampleStatus(sampleStatus);
        toolsCheckRecordService.sample(toolsCheckRecord);
        return R.ok();
    }

}
